#include "ConverterApp.h"

namespace GC
{
	boost::function<void( const wchar_t*, const bool)> ConverterApp::s_logMessage;
	ConverterSettingsPtr ConverterApp::s_settings;

	ConverterApp::ConverterApp(const _TCHAR* a_inputFile,const _TCHAR* a_outputFile, const ConverterType a_converterType)		
	{			
		s_settings = std::make_shared<ConverterSettings>();
		
		Initialize(a_inputFile, a_outputFile, a_converterType);
	}

	ConverterApp::ConverterApp(const _TCHAR* a_inputFile,const _TCHAR* a_outputFile, const ConverterType a_converterType,ConverterSettings* a_settings = nullptr)
	{		
		if (a_settings != nullptr)
		{			
			s_settings = ConverterSettingsPtr(a_settings);
		}
		else
		{
			s_settings = std::make_shared<ConverterSettings>();
		}	
		
		Initialize(a_inputFile, a_outputFile, a_converterType);
	}

	void ConverterApp::Initialize(const _TCHAR* a_inputFile, const _TCHAR* a_outputFile, const ConverterType a_converterType)
	{
		if (a_converterType == ConverterType::Fbx)
		{			
			m_converter = FbxConverterPtr(new FbxConverter(a_inputFile, a_outputFile));
			
			m_initiated = true;
		}
		else
		{
			m_initiated = false;
		}
	}

	ConverterApp::~ConverterApp()
	{		
	}

	const int ConverterApp::RunConverter( boost::function<void( const wchar_t* a_message, const bool a_newLine)> a_logMessage )
	{		
		if (!m_initiated || m_converter == nullptr)
		{
			return Status::Failed;
		}
		
		s_logMessage = a_logMessage;
		//That's the specialized converter!
		m_converter->Run();

		return Status::Failed;
	}

	const ConverterSettingsPtr ConverterApp::GetSettings()
	{				
		return s_settings;
	}
	
}